package clone;


//自定义的类型想要被克隆必须实现克隆接口
public class Person implements Cloneable {
    private int age;
    public Money m;

    public Person(int age) {
        this.age = age;
        this.m = new Money();
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }


    @Override
    public String toString() {
        return "Person{" +
                "age=" + age +
                '}';
    }

    @Override
    protected Object clone() throws CloneNotSupportedException {
        //浅克隆
//        return super.clone();

        Person tmp = (Person) super.clone();
        //深克隆 把克隆对象里面的对象也进行了克隆
        tmp.m = (Money) this.m.clone();
        return tmp;
    }
}
